package com.zytlifeservice.repository.find;

import com.zytlifeservice.domain.find.Commodity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 积分商品持久接口
 * Created by Administrator on 2017/5/31.
 */
@Repository
public interface CommodityRepository extends JpaRepository<Commodity,Long>{

    //查询所有可兑换的积分商品
    @Query(value = "select  c  from Commodity c  where  pcount>0")
    public List<Commodity> findAllList();

    //减少商品数量
    @Modifying(clearAutomatically = true)
    @Query(value = "update commodity set pcount=pcount-?1 where pid=?2 ",nativeQuery = true)
    public Integer updateCount(Integer pcount, Long pid);

}
